<?php
/**
 * Created by PhpStorm.
 * User: 86182
 * Date: 2020/6/26
 * Time: 13:31
 */

namespace App\Serves;
use App\Models\User;
use App\Utils\Token;

use Illuminate\Http\Request;


class UserServe
{
    public  $userName = '';
    public  function doUserCheck(Request $request, $phone){
        $user = User::where('phone', $phone)->first();
        if(!$user){
            //没有则插入新用户数据
            $user = new User;
            $user->phone = $phone;
            $user->name = '无名小伙伴'.$phone;
            $res = $user->save();
            if(!$res){
                return false;
            }
        }else{
            //更新登录信息，登陆时间等

        }
        $user = $user->toArray();

        $data = [
            'userName'=>$user['name'],
            'userId'=>$user['id'],
//            'token'=>Token::getToken()
        ];

        $this->userName = $user['name'];
        $request->session()->put('user', $data);

        return $data;

    }
}